home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 2.8 KB | 98 lines | [TEXT/ttxt] |
- -- <<<-
-
- -- selectbl.sx
- -- Event Receiver example
- -- by Doug Kramer
- -- demonstrates receiving mouse events on presenters
- -- from "Events and Input Devices" chapter of
- -- ScriptX Components Guide
-
- module EventTest1 uses ScriptX end
- in module EventTest1
-
- -- A mixin class
- class Selectable (RootObject)
- instance variables
- mouseDown -- For setting up an interest in mouse down events
- mouseUp -- For setting up an interest in mouse up events
- selectionBox -- Appears around the presenter to highlight it
- end
-
- -- Define the method that is called when mouse-up occurs
- method mouseDownSelect self {class Selectable} theInterest theEvent ->
- (
- -- Move the 2D presenter to the front of its container
- moveToFront self.presentedBy self
-
- -- Create a selection rectangle that just fits the 2D presenter
- self.selectionBox := new TwoDShape
- self.selectionBox.target :=(new Rect x2:self.bBox.x2 y2:self.bBox.y2)
- self.selectionBox.stroke := new Brush color:yellowColor
- self.selectionBox.x := self.x
- self.selectionBox.y := self.y
- self.selectionBox.stroke.linewidth := 2
- prepend self.presentedBy self.selectionBox
-
- -- Now we're interested only in mouse up events
- removeEventInterest self.mouseDown
- addEventInterest self.mouseUp
- @accept -- must accept for event to be swallowed
- )
-
- -- Define the method that is called when mouse-up occurs
- method mouseUpSelect self {class Selectable} theInterest theEvent ->
- (
- deleteOne self.presentedBy self.selectionBox
-
- -- now we're interested only in mouse down events
- removeEventInterest self.mouseUp
- addEventInterest self.mouseDown
- @accept -- must accept for event to be swallowed
- )
-
- method init self {class Selectable} #rest args ->
- (
- apply nextMethod self args -- call init on superclass
-
- -- set up the mouse event interests
- self.mouseDown := new MouseDownEvent
- self.mouseDown.eventReceiver := mouseDownSelect
- self.mouseDown.authorData := self
- self.mouseDown.presenter := self
-
- self.mouseUp := new MouseUpEvent
- self.mouseUp.eventReceiver := mouseUpSelect
- self.mouseUp.authorData := self
- self.mouseUp.presenter := self
- self.mouseUp.matchedInterest := self.mouseDown
-
- -- Initially, we're interested in mouse down events
- addEventInterest self.mouseDown
- )
-
- -- Set up a simple example of black and red rectangles in a window
- global myWindow := new Window boundary:(new Rect x2:300 y2:300)
- myWindow.x := 40
- myWindow.y := 40
- show myWindow
-
- -- Create the black rectangle
- object myBlackRect (Selectable, TwoDShape)
- end
- myBlackRect.target := new Oval x2:100 y2:100
- myBlackRect.fill := blackBrush
- myBlackRect.x := 75
- myBlackRect.y := 75
- prepend myWindow myBlackRect
-
- -- Create the red rectangle
- object myRedRect (Selectable, TwoDShape)
- end
- myRedRect.target := new Rect x2:100 y2:100
- myRedRect.fill := new Brush color:redColor
- myRedRect.x := 125
- myRedRect.y := 125
- prepend myWindow myRedRect
-
- -- >>>
-